/**
 * Created by jack on 2017/12/14.
 */
'use strict';

goog.provide('Blockly.JavaScript.motion');

goog.require('Blockly.JavaScript');


Blockly.JavaScript['motion_movesteps'] = function(block) {
  var value_steps = Blockly.JavaScript.valueToCode(block, 'STEPS', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var code = 'ActionBlock.move('+value_steps+',0);\n';
  return code;
};


Blockly.JavaScript['motion_turnright'] = function(block) {
  var value_rotates = Blockly.JavaScript.valueToCode(block, 'DEGREES', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var code = 'ActionBlock.rotate('+value_rotates+',0);\n';
  return code;
};

Blockly.JavaScript['motion_turnleft'] = function(block) {
  var value_rotates = Blockly.JavaScript.valueToCode(block, 'DEGREES', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var code = 'ActionBlock.rotate(-'+value_rotates+',0);\n';
  return code;
};


Blockly.JavaScript['motion_pointindirection'] = function(block) {
  var value_rotates = Blockly.JavaScript.valueToCode(block, 'DIRECTION', Blockly.JavaScript.ORDER_NONE);
  // TODO: Assemble JavaScript into code variable.
  var code = 'ActionBlock.rotateTo('+value_rotates+',0);\n';
  return code;
};

Blockly.JavaScript['motion_gotoxy'] = function(block) {
    var value_x = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_ATOMIC);
    var value_y = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.JavaScript.ORDER_ATOMIC);
    var code = 'ActionBlock.moveTo('+value_x+','+value_y+',0);\n';
    return code;
};

Blockly.JavaScript['motion_setx'] = function(block) {
    var value_x = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_ATOMIC);
    var code = 'ActionBlock.moveTo('+value_x+',NaN,0);\n';
    return code;
};


Blockly.JavaScript['motion_sety'] = function(block) {
    var value_y = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.JavaScript.ORDER_ATOMIC);
    var code = 'ActionBlock.moveTo(NaN,'+value_y+',0);\n';
    return code;
};

Blockly.JavaScript['motion_xposition'] = function(block) {
   var code="ActionBlock.getInfo()['x']";
    return [code, Blockly.JavaScript.ORDER_ATOMIC];
};

Blockly.JavaScript['motion_yposition'] = function(block) {
   var code="ActionBlock.getInfo()['y']";
    return [code, Blockly.JavaScript.ORDER_ATOMIC];
};

Blockly.JavaScript['motion_direction'] = function(block) {
   var code="ActionBlock.getInfo()['r']";
    return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
